# 请求https需要忽略ssl认证
from urllib.request import Request
import urllib.request as ur
import ssl

# 1. 表示忽略未经核实的SSL证书认证
context = ssl._create_stdlib_context()

url = "https://www.12306.cn/mormhweb/"

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}

request = Request(url, headers = headers)

# 2. 在urlopen()方法里 指明添加 context 参数
response = ur.urlopen(request, context = context)

print(response.read().decode('utf8'))